package flater.cairngormtips.controller.commands
{

import com.adobe.cairngorm.control.CairngormEvent;
import com.universalmind.cairngorm.commands.Command;

import flater.cairngormtips.controller.delegates.DataTranslatorExampleDelegate;
import flater.cairngormtips.model.Model;
import flater.cairngormtips.util.out;

import mx.collections.ArrayCollection;


/**
 *  Retrieves a set of items using the 
 *  <code>DataTranslatorExampleDelegate<code> class. <br/> 
 *  <br/>
 *  Author: <a href="http://www.adamflater.net" target="_blank">
 *  Adam Flater</a>
 *  <br/>
 *  @see flater.cairngormtips.controller.delegates.DataTranslatorExampleDelegate
 *  @see flater.cairngormtips.controller.events.GetItemsEvent
 *  @see flater.cairngormtips.DataTranslatorExampleApplication                                                                                          
 */
public class ItemsCommand extends Command
{
    public function ItemsCommand()
    {
        out( "ItemsCommand Instantiated" );
          
        super();
    }
    
	override public function execute( event : CairngormEvent ) : void
	{
        super.execute( event );

        out( "ItemsCommand.execute() invoked" );
          
		var delegate : DataTranslatorExampleDelegate = 
		                  new DataTranslatorExampleDelegate( this );
            delegate.getItems();
	}
	
	override public function result( info : Object ) : void
	{
        out( "ItemsCommand.result() invoked" );
        
		var items   : Array            = info as Array;
		var itemsAC : ArrayCollection  = new ArrayCollection( items );
		
		Model.getInstance().items      = itemsAC;
		
		notifyCaller( itemsAC );
	}
	
} //  end class
} //  end package